<template>
  <el-table :data="tableData" style="width: 100%" height="800"
            :header-cell-style="{background:'#703CF6',color:'#fdfdfd',textAlign: 'center'}"
            :cell-style="{ textAlign: 'center' }"
  >
    <el-table-column prop="fileId"  label="文件ID" width="300px"/>
    <el-table-column prop="feedTxt" label="反馈描述" width="300px"/>
    <el-table-column prop="fileHash" label="文件哈希" width="300px"/>
    <el-table-column label="回复" width="300px">
      <template v-slot="scope">
        <el-button color="#626aef"
                   :dark="isDark"
                   plain
                   @click="readReply(scope.row.id)"
                   v-if="scope.row.isReplied==1" >查看回复</el-button>
        <el-button color="#626aef"
                   :dark="isDark"
                   plain
                   @click="readReply(scope.row.id)"
                   v-if="scope.row.isReplied==null"
                   disabled>尚未回复</el-button>
      </template>

    </el-table-column>
  </el-table>

  <!--回复-->
  <el-dialog
      v-model="replyView"
      title="查看回复"
      width="65%"
      ref="ruleForm"
      class="digTop"
  >
    <el-form
        ref="rulesForm"
        :model="rulesForm"
        :rules="formRules"
        label-width="120px"
    >
      <el-form-item

      >
        {{reply}}
      </el-form-item>

    </el-form>
  </el-dialog>
</template>

<script>
import axios from "axios";
import {ElMessage} from "element-plus";

export default {
  name: "feedback-form",
  created() {
    this.getData()
  },
  computed: {
    userId(){
      return JSON.parse(sessionStorage.getItem('userObj')).id;
    }
  },


  data(){
    return{
      reply:'',
      tableData: [],
      replyView:false
    }
  },
  methods:{
    getData(){
      axios.get('http://120.48.51.66:8081/feedback/getFeedbackListById'
          , {
            params:{
              userId:this.userId
            }
          }).then(response => {
        if (response.data.code==200) {
          this.tableData=response.data.data.feedbackList;
        } else {
          ElMessage({
            message: "获取反馈失败",
            type: "error"
          });
        }
      });
    },
    readReply(id){
      axios.get('http://120.48.51.66:8081/feedback/getFeedbackById'
          , {
            params:{
              feedbackId:id
            }
          }).then(response => {
        if (response.data.code==200) {
if(response.data.data.feedback.isReplied){
  this.reply=response.data.data.feedback.reply;
}else{
  this.reply='管理员尚未回复'
}

        } else {
          ElMessage({
            message: "获取回复失败",
            type: "error"
          });
        }
      });

    this.replyView=true
    }



  },

}

</script>

<style scoped>

</style>
